import { z } from "zod";

// 用户信息
export const UserSchema = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string().optional(),
  avatar_url: z.string().optional(),
});

// 仓库成员
export const RepoMemberSchema = z.object({
  id: z.string(),
  user: UserSchema,
  access_level: z.number(),
  role: z.string(),
});

// 仓库信息
export const RepositorySchema = z.object({
  id: z.string(),
  name: z.string(),
  path: z.string(),
  description: z.string().optional(),
  visibility: z.enum(["private", "public"]),
  created_at: z.string(),
  updated_at: z.string(),
  owner: UserSchema,
  project_id: z.string(),
  web_url: z.string(),
  ssh_url: z.string().optional(),
  http_url: z.string().optional(),
});

// 项目信息
export const ProjectSchema = z.object({
  id: z.string(),
  name: z.string(),
  description: z.string().optional(),
  visibility: z.enum(["private", "public"]),
  created_at: z.string(),
  updated_at: z.string(),
  owner: UserSchema,
  web_url: z.string(),
});

// Webhook
export const WebhookSchema = z.object({
  id: z.string(),
  url: z.string(),
  events: z.array(z.string()),
  enabled: z.boolean(),
  created_at: z.string(),
  updated_at: z.string(),
});

// 提交信息
export const CommitSchema = z.object({
  id: z.string(),
  short_id: z.string(),
  title: z.string(),
  message: z.string(),
  author_name: z.string(),
  author_email: z.string(),
  committer_name: z.string().optional(),
  committer_email: z.string().optional(),
  created_at: z.string(),
  parent_ids: z.array(z.string()).optional(),
});

// 文件内容
export const FileContentSchema = z.object({
  name: z.string(),
  type: z.enum(["file", "dir"]),
  size: z.number().optional(),
  encoding: z.string().optional(),
  content: z.string().optional(),
  path: z.string(),
  sha: z.string().optional(),
});

// 分支信息
export const BranchSchema = z.object({
  name: z.string(),
  commit: CommitSchema,
  protected: z.boolean(),
  merged: z.boolean().optional(),
});

// 分页信息
export const PaginationSchema = z.object({
  page: z.number(),
  per_page: z.number(),
  total: z.number(),
  total_pages: z.number(),
});

// 搜索结果
export const SearchResultSchema = z.object({
  items: z.array(z.any()),
  pagination: PaginationSchema,
});

// 工作项关联
export const IssueAssociationSchema = z.object({
  issue_id: z.string(),
  branch_id: z.string(),
  project_id: z.string(),
});

// 类型导出
export type User = z.infer<typeof UserSchema>;
export type RepoMember = z.infer<typeof RepoMemberSchema>;
export type Repository = z.infer<typeof RepositorySchema>;
export type Project = z.infer<typeof ProjectSchema>;
export type Webhook = z.infer<typeof WebhookSchema>;
export type Commit = z.infer<typeof CommitSchema>;
export type FileContent = z.infer<typeof FileContentSchema>;
export type Branch = z.infer<typeof BranchSchema>;
export type Pagination = z.infer<typeof PaginationSchema>;
export type SearchResult = z.infer<typeof SearchResultSchema>;
export type IssueAssociation = z.infer<typeof IssueAssociationSchema>; 